/*  This file is part of the comicconquer project
    Copyright (C) 2010 Reach <reach334@gmail.com>

    ComicConquer is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This software is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public 
    License along with this software.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "KeyViewWidget.h"

extern CoListItems g_mainOperations;
extern CoListItems g_keys;

// key view column
KeyViewWidget::KeyViewWidget(QString keyName, CoListItem* operItem, QWidget* parent) : QWidget(parent)
{
    In_Log(__FUNCTION__, COCLASSNAME);

    m_operItem = operItem;

    QHBoxLayout* mainlayout = new QHBoxLayout(this);
    setLayout(mainlayout);

    m_label = new ui::OnyxLabel(keyName, this);
    mainlayout->addWidget(m_label);
    mainlayout->addSpacing(300);

    m_button = new ui::OnyxPushButton(m_operItem->str, this);
    mainlayout->addWidget(m_button);

    connect(m_button, SIGNAL(clicked()), this, SLOT(buttonClicked()));

    Out_Log(__FUNCTION__, COCLASSNAME);
}

void KeyViewWidget::buttonClicked()
{
    In_Log(__FUNCTION__, COCLASSNAME);

    CoListItem* item = CoListDlg::select(&g_mainOperations);
    parentWidget()->parentWidget()->update();
    if (item != NULL)
    {
        m_operItem = item;
        m_button->setText(item->str);
    }

    Out_Log(__FUNCTION__, COCLASSNAME);
}
